package com.selfdriving.adapter;

import java.util.List;
import javax.crypto.spec.IvParameterSpec;

import net.tsz.afinal.FinalBitmap;

import com.selfdriving.BaseApplication;
import com.selfdriving.R;
import com.selfdriving.bean.DetailEntity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class DiaryDetailsAdapter extends BaseAdapter
{

	private Context context;

	private List<DetailEntity> detailEntities;

	private OnClickListener onClickListener;

	private static final int TIME_DATE = 0x1;

	private static final int TIME_PICTURE = 0x2;

	private static final int TIME_ERROR = 0x3;

	private HolderView holderView;
	protected FinalBitmap fb;
	private BaseApplication application;

	public DiaryDetailsAdapter(BaseApplication application, Context context,
			List<DetailEntity> detailEntities, OnClickListener onClickListener)
	{
		this.context = context;
		this.application = application;
		this.detailEntities = detailEntities;
		this.onClickListener = onClickListener;
		fb = FinalBitmap.create(context);
	}

	@Override
	public int getCount()
	{
		return detailEntities.size();
	}

	@Override
	public Object getItem(int arg0)
	{
		return detailEntities.get(arg0);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public int getItemViewType(int position)
	{
		if (detailEntities.get(position).flag == 1)
		{
			return TIME_DATE;
		} else
		{
			return TIME_PICTURE;
		}
	}

	@Override
	public int getViewTypeCount()
	{
		return TIME_ERROR;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		DetailEntity detailEntity = detailEntities.get(position);
		int type = getItemViewType(position);
		if (convertView == null)
		{
			holderView = new HolderView();
			switch (type)
			{
			case TIME_DATE:
				convertView = ((LayoutInflater) context
						.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
						.inflate(R.layout.strategy_item_one, null);
				break;
			case TIME_PICTURE:
				convertView = ((LayoutInflater) context
						.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
						.inflate(R.layout.strategy_item_sec, null);
				holderView.comment = (ImageView) convertView
						.findViewById(R.id.ivComment);
				holderView.bigImg = (ImageView) convertView
						.findViewById(R.id.item_sec_img);
				holderView.comment.setOnClickListener(onClickListener);
				break;
			}
			convertView.setTag(holderView);
		} else
		{
			holderView = (HolderView) convertView.getTag();
		}
		switch (type)
		{
		case TIME_DATE:

			break;

		case TIME_PICTURE:
			fb.display(
					holderView.bigImg,
					"http://d.hiphotos.baidu.com/image/w%3D2048/sign=4038c14ea38b87d65042ac1f33302938/6c224f4a20a44623fad3d61d9a22720e0cf3d7b0.jpg");
			break;
		}
		holderView.icon = (ImageView) convertView.findViewById(R.id.ivTimeLine);
		return convertView;
	}

	private class HolderView
	{

		private ImageView icon;

		private ImageView comment;

		private ImageView bigImg;

	}

}
